package com.eshin.autotest.controller;

import com.eshin.autotest.listener.DemoEvent;
import com.eshin.autotest.service.HelloConfiguration3;
import com.eshin.autotest.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Import;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Eshin
 * @title: HelloController
 * @projectName pay
 * @date 2019/5/2815:51
 */

@RestController
@Import(HelloConfiguration3.class)
public class HelloController {

    @Value("${spring.pbe.test}")
    public String test;

    public List<String> hello = new ArrayList<>();

    @Autowired
    ApplicationContext context;

    @Autowired
    HelloService service;

    public void initController(){
        System.out.println("HelloController invoke initController()..."+":"+test+":"+hello);
    }
    @PostConstruct
    public void init(){
        System.out.println("HelloController invoke init()..."+":"+test+":"+hello);
    }

//    @Autowired
//    OrderBean orderBean;

    @RequestMapping("/hello")
    public String sayHello(){
        System.out.println(Thread.currentThread().getName());
//        System.out.println(orderBean.getName());
        service.doService();
        context.publishEvent(new DemoEvent(this, "22"));
        return "hello";
    }
}
